package com.lucien.system.transverter;

import com.lucien.system.domain.ChatMessage;
import com.lucien.system.domain.SysGroupMessage;
import com.lucien.system.mapper.SysGroupMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @Author Lucien
 * @Date 2021/6/13 22:04
 * @Version 1.0
 * @Description: groupmessage转为chatmessage
 */
@Component
public class GroupMsgToChatMsg {

    @Autowired
    private SysGroupMapper groupMapper;

    public static ChatMessage toChatMsg(SysGroupMessage groupMessage, String groupName){
        ChatMessage chatMessage = new ChatMessage();
        chatMessage.setId(Math.toIntExact(groupMessage.getId()));
        chatMessage.setFromId(groupMessage.getUserId());
        chatMessage.setFromName(groupMessage.getUsername());
        chatMessage.setFromProfile(groupMessage.getUserProfile());
        chatMessage.setToId(groupMessage.getGroupId());
        chatMessage.setToName(groupName);
        chatMessage.setMessageTypeId(groupMessage.getMessageTypeId());
        chatMessage.setCreateTime(groupMessage.getCreateTime());
        chatMessage.setContent(groupMessage.getContent());

        return chatMessage;
    }
}
